import { NodeSize } from '../config'

export default function sendMail(flow) {
  flow.register('SendMail', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#436580"',
              d: 'M948.14 128.044H76.3c-42.007 0-76.06 34.054-76.06 76.062v615.787c0 42.008 34.053 76.062 76.06 76.062h871.84c42.008 0 76.062-34.054 76.062-76.062V204.106c0-42.008-34.054-76.062-76.062-76.062z m33.399 691.85c0 18.416-14.982 33.398-33.399 33.398H76.3c-18.416 0-33.399-14.982-33.399-33.399V294.934l457.44 297.753 0.092 0.055c0.372 0.24 0.75 0.467 1.135 0.681 0.067 0.038 0.133 0.078 0.2 0.115 0.412 0.224 0.83 0.437 1.255 0.632l0.1 0.05c0.422 0.192 0.852 0.369 1.286 0.534 0.236 0.09 0.476 0.167 0.713 0.247 0.198 0.067 0.393 0.136 0.592 0.197 0.273 0.084 0.548 0.158 0.824 0.231 0.168 0.044 0.336 0.088 0.506 0.128 0.285 0.068 0.568 0.129 0.854 0.184 0.17 0.034 0.342 0.063 0.515 0.092 0.28 0.047 0.558 0.093 0.838 0.13 0.201 0.025 0.404 0.043 0.605 0.064 0.25 0.024 0.502 0.053 0.753 0.07 0.358 0.023 0.718 0.032 1.078 0.037 0.089 0.001 0.179 0.01 0.268 0.01l0.02-0.002 0.02 0.001c0.09 0 0.18-0.008 0.269-0.009 0.36-0.005 0.718-0.014 1.077-0.038 0.25-0.016 0.501-0.044 0.75-0.068 0.203-0.02 0.406-0.038 0.608-0.065 0.279-0.036 0.556-0.08 0.833-0.128 0.174-0.03 0.348-0.059 0.521-0.093a20.25 20.25 0 0 0 1.36-0.314c0.276-0.073 0.55-0.146 0.822-0.231 0.198-0.06 0.393-0.13 0.588-0.196 0.24-0.081 0.48-0.158 0.719-0.25 0.433-0.163 0.86-0.34 1.282-0.531l0.119-0.059c0.417-0.193 0.829-0.402 1.235-0.622 0.072-0.04 0.143-0.083 0.215-0.123 0.378-0.212 0.75-0.435 1.117-0.67 0.033-0.021 0.068-0.039 0.1-0.06l457.925-298.069v525.276z m0-576.177l-469.56 305.642L42.902 244.032v-39.925c0-18.417 14.983-33.4 33.4-33.4h871.84c18.416 0 33.398 14.983 33.398 33.4v39.61z"'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '发送邮件'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
